package com.pai4j.pgc.service.relation;
import com.pai4j.domain.vo.response.subjectaccount.SubjectBaseResponseVO;
import com.pai4j.pgc.entity.SubjectSubscribeEntity;
import com.pai4j.pgc.service.SubjectService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class SubjectRelationService{
    
    @Resource
    private SubjectService subjectService;
    /**
     * 订阅/关注
     *
     * @param userId
     * @param subjectId
     * @return
     */
    public Boolean subscribe(String userId, Long subjectId) {
        SubjectBaseResponseVO targetAccountInfo = subjectService.getSubjectBaseInfo(subjectId);
        Integer roleCode = targetAccountInfo.getRoleCode();
        return SubjectRelationFactory.getServiceByCode(roleCode).subscribe(userId, subjectId);
    }

    /**
     * 取消订阅/关注
     *
     * @param userId
     * @param subjectId
     * @return
     */
    public Boolean unsubscribe(String userId, Long subjectId) {
        SubjectBaseResponseVO targetAccountInfo = subjectService.getSubjectBaseInfo(subjectId);
        Integer roleCode = targetAccountInfo.getRoleCode();
        return SubjectRelationFactory.getServiceByCode(roleCode).unsubscribe(userId, subjectId);
    }
    
    
    /**
     * 获取用户订阅/关注状态: 判断是否已订阅/关注
     *
     * @param userId
     * @param subjectId
     * @return
     */
    public Boolean isSubscribe(Integer relationType, String userId, Long subjectId) {
        
        return SubjectRelationFactory.getServiceByType(relationType).isSubscribe(userId, subjectId);
    }
    
    
    /**
     * 获取当前专题的订阅列表
     *
     * @param relationType
     * @param subjectId
     * @return
     */
    public Set<String> getAllSubscriber(Integer relationType, Long subjectId) {
        return SubjectRelationFactory.getServiceByType(relationType).getAllSubscriber(subjectId);
    }
    
    
}
